//
//  MaskBackView.m
//  UtilityClass
//
//  Created by xiong qi on 11-11-23.
//  Copyright (c) 2011年 AppFactory. All rights reserved.
//

#import "MaskBackView.h"

@implementation MaskBackView
@synthesize delegate,ReceiveRecognize;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.5]];
        
    }
    return self;
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch * touch = [touches anyObject];
    if (touch.view == self) {
        [self RemoveView];
    }
}

-(void)setReceiveRecognize:(BOOL)value
{
    if(value)
    {
        recognizer_Right = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeRight:)]; 
        [self addGestureRecognizer:recognizer_Right];
        [recognizer_Right release];
        
        recognizer_Left = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeLeft:)]; 
        [recognizer_Left setDirection:UISwipeGestureRecognizerDirectionLeft]; 
        [self addGestureRecognizer:recognizer_Left];
        [recognizer_Left release];
    }
    else
    {
        
    }
    ReceiveRecognize = value;
}


-(void)handleSwipeLeft:(UISwipeGestureRecognizer *)recognizer { 
    
    if (recognizer.direction == UISwipeGestureRecognizerDirectionLeft) {
        if([delegate respondsToSelector:@selector(MoveLeft)]) {
            [delegate MoveLeft];
        }
    }
}

-(void)handleSwipeRight:(UISwipeGestureRecognizer *)recognizer { 
    if (recognizer.direction == UISwipeGestureRecognizerDirectionRight) {
        if([delegate respondsToSelector:@selector(MoveRight)]) {
            [delegate MoveRight];
        }
    }
}

-(void)RemoveView
{
    if (self.delegate == nil) {
        [self removeFromSuperview];
    }
    else if([delegate respondsToSelector:@selector(RemoveView)]) {
        [delegate RemoveView];
    }
    
}

-(void)MoveLeft
{
    
}

-(void)MoveRight
{
    
}

-(void)dealloc
{
    SafeRelease(recognizer_Right);
    SafeRelease(recognizer_Left);
    self.delegate = nil;
    [super dealloc];
}

@end
